{include file="public/header" /}

<div class="page">
    <form id="user_form" enctype="multipart/form-data" action="{:url('member_save')}" method="post">
        <input type="hidden" name="member_id" value="{if condition="isset($member_array['member_id'])"}{$member_array.member_id}{/if}" />
        <input type="hidden" name="old_member_avatar" value="{if condition="isset($member_array['member_avatar'])"}{$member_array.member_avatar}{/if}" />
        <input type="hidden" name="member_name" value="{if condition="isset($member_array['member_name'])"}{$member_array.member_name}{/if}" />
        <table class="sc-default-table">
            <tbody>
            <tr class="noborder">
                <td class="required"><label class="validation" for="inviter_name">代理商名称:</label></td>
                <td class="vatop rowform"><input type="text" value="{if condition="isset($member_array['inviter_name'])"}{$member_array.inviter_name}{/if}" id="inviter_name" name="inviter_name" class="txt"></td>
                <td class="vatop tips"></td>
            </tr>
            <tr class="noborder">
                <td class="required w120"><label class="validation">账号:</label></td>
                <td class="vatop rowform"><input type="text" id="member_name" name="member_name" value="{if condition="isset($member_array['member_name'])"}{$member_array.member_name}{/if}" class="txt"></td>
                <td class="vatop tips"></td>
            </tr>
            <tr class="noborder">
                <td class="required"><label class="member_mobile validation">登录手机:</label></td>
                <td class="vatop rowform"><input type="text" value="{if condition="isset($member_array['member_mobile'])"}{$member_array.member_mobile}{/if}" id="member_mobile" name="member_mobile" class="txt"></td>
                <td class="vatop tips"></td>
            </tr>
            <tr class="noborder">
                <td class="required"><label {if !isset($member_array['member_id'])}class="validation"{/if} for="member_password">{$Think.lang.member_edit_password}:</label></td>
                <td class="vatop rowform"><input type="text" id="member_password" name="member_password" class="txt"></td>
                <td class="vatop tips"></td>
            </tr>
            <tr class="noborder">
                <td class="required"><label for="member_paypwd">支付密码:</label></td>
                <td class="vatop rowform"><input type="text" id="member_paypwd" name="member_paypwd" class="txt"></td>
                <td class="vatop tips"></td>
            </tr>
            <tr class="noborder">
                <td class="required"><label class="member_areainfo validation">地址:</label></td>
                <td class="vatop rowform"  colspan="2">
                        <span  class="w400">
                      <input type="hidden" value="{if condition="isset($member_array['inviter_provinceid'])"}{$member_array['inviter_provinceid']|default=''}{/if}" name="province_id" id="_area_1">
                      <input type="hidden" value="{if condition="isset($member_array['inviter_cityid'])"}{$member_array['inviter_cityid']|default=''}{/if}" name="city_id" id="_area_2">
                      <input type="hidden" value="{if condition="isset($member_array['inviter_areaid'])"}{$member_array['inviter_areaid']|default=''}{/if}" name="area_id" id="_area_3">
                      <input type="hidden" name="region" id="region" value="{if condition="isset($member_array['inviter_areainfo'])"}{$member_array.inviter_areainfo}{/if}"/>
                        </span>
                </td>
            </tr>
            <tr class="noborder">
                <td class="required"><label class="validation" for="inviter_id">邀请码:</label></td>
                <td class="vatop rowform"><input type="text" value="{if condition="isset($member_array['inviter_code'])"}{$member_array.inviter_code}{/if}" id="inviter_id" name="inviter_id" class="txt"></td>
                <td class="vatop tips"></td>
            </tr>
            <tr class="noborder">
                <td class="required"><label for="inviter_contact_name">联系人:</label></td>
                <td class="vatop rowform"><input type="text" value="{if condition="isset($member_array['inviter_contact_name'])"}{$member_array.inviter_contact_name}{/if}" id="inviter_contact_name" name="inviter_contact_name" class="txt"></td>
                <td class="vatop tips"></td>
            </tr>
            <tr class="noborder">
                <td class="required"><label for="inviter_contact_mobile">联系人手机:</label></td>
                <td class="vatop rowform"><input type="text" value="{if condition="isset($member_array['inviter_contact_mobile'])"}{$member_array.inviter_contact_mobile}{/if}" id="inviter_contact_mobile" name="inviter_contact_mobile" class="txt"></td>
                <td class="vatop tips"></td>
            </tr>

            <tr class="noborder">
                <td class="required"><label class="validation">状态:</label></td>
                <td class="vatop rowform onoff">
                    <label for="inviter_state_0" class="cb-enable {if isset($member_array['inviter_state']) && $member_array.inviter_state == '0'}selected {/if}" ><span>未激活</span></label>
                    <label for="inviter_state_1" class="cb-disable {if isset($member_array['inviter_state']) && $member_array.inviter_state == '1'}selected{/if}" ><span>激活</span></label>
                    <input id="inviter_state_0" name="inviter_state" {if isset($member_array['inviter_state']) && $member_array.inviter_state == '0'}checked="checked"{/if}  value="0" type="radio">
                    <input id="inviter_state_1" name="inviter_state" {if isset($member_array['inviter_state']) && $member_array.inviter_state == '1'}checked="checked"{/if} value="1" type="radio">
                </td>
                <td class="vatop tips"></td>
            </tr>
            </tbody>
            <tfoot>
            <tr class="tfoot">
                <td colspan="15"><a href="JavaScript:void(0);" class="btn" id="submitBtn"><span>{$Think.lang.sc_submit}</span></a></td>
            </tr>
            </tfoot>
        </table>
    </form>

    <script type="text/javascript" src="{$Think.PLUGINS_SITE_ROOT}/mlselection.js" charset="utf-8"></script>
    <script type="text/javascript">
        $(function() {
            {if !isset($member_array['inviter_ratio']) || $member_array['inviter_ratio'] == 0}
            // 切换类别设置默认比例
            $('[id^="inviter_type_"]').click(function () {
                var inviter_type = $(this).val();
                if(inviter_type == 1) {
                    $('#inviter_ratio').val('{$Think.config.inviter_ratio_1}');
                } else {
                    $('#inviter_ratio').val('{$Think.config.inviter_ratio_2}');
                }
            }).filter(':checked').click();
            {/if}

            $("#region").sc_region();
            $("#submitBtn").click(function() {
                if ($("#user_form").valid()) {
                    $("#user_form").submit();
                }
            });
            $('#user_form').validate({
                errorPlacement: function(error, element) {
                    error.appendTo(element.parent().parent().find('td:last'));
                },
                rules: {
                    inviter_name: {
                        required: true,
                    },
                    member_name: {
                        required: true,
                        maxlength: 50,
                        minlength: 3,
                    },
                    member_mobile: {
                        required: true,
                        digits : true,
                        maxlength: 11,
                        minlength: 11
                    },
                    member_password: {
                        // required: true,
                        maxlength: 20,
                        minlength: 6
                    },
                    area_id:{
                        required: true,
                    },
                    inviter_id:{
                        required: true,
                    },
                    member_email: {
                        required: true,
                        email: true,
                        remote: {
                            url: ADMINSITEURL+'/Member/ajax.html?branch=check_email',
                            type: 'get',
                            data: {
                                user_name: function() {
                                    return $('#member_email').val();
                                },
                                member_id : '{if condition="isset($member_array['member_id'])"}{$member_array.member_id}{/if}'
                            }
                        }
                    },

                },
                messages: {
                    inviter_name: {
                        required: '代理商名不能为空',
                    },
                    member_name: {
                        required: '账号不能为空',
                        maxlength: '账号最多为50个字符',
                        minlength: '账号最小3个字符'
                    },
                    member_mobile: {
                        required: '手机号不能为空',
                        digits : '手机号必须为纯数字',
                        maxlength: '请输入正确格式的手机号',
                        minlength: '请输入正确格式的手机号'
                    },
                    member_password: {
                        // required:'密码不能为空',
                        maxlength: '{$Think.lang.member_edit_password_tip}',
                        minlength: '{$Think.lang.member_edit_password_tip}'
                    },
                    area_id:{
                        required: '请选择所在地区',
                    },
                    inviter_id: {
                        required: '邀请码不能为空',
                    },
                    member_email: {
                        required: '{$Think.lang.member_edit_email_null}',
                        email: '{$Think.lang.member_edit_valid_email}',
                        remote: '{$Think.lang.member_edit_email_exists}'
                    }
                }
            });

           $(function() {
                layer.photos({
                    photos: '.rowform'
                    ,anim: 4 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
                });
            })
        });
    </script>
</div>
